﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace Clotho.Novelview {
	public class ViewFeature : IFeature {
		public const string TYPEWORD = "显示";
		public override string Type_word => TYPEWORD;
		Point location;
		public Action<ViewFeature> eLocationChanged;
		public Point Location { get {
				return location;
			} set {
				var old = location;
				Nov.doCmd(() => {
					location = value;
					eLocationChanged?.Invoke(this);
				},() => {
					location = old;
					eLocationChanged?.Invoke(this);
				});
			}
		}
		public void move(int x,int y) {
			Nov.doCmd(() => {
				location.Offset(x, y);
				eLocationChanged?.Invoke(this);
			},() => {
				location.Offset(-x, -y);
				eLocationChanged?.Invoke(this);
			});
		}
		public Action<ViewFeature> eSizeChanged;
		Size size;
		public Size Size {
			get {
				return size;
			}
			set {
				var old = size;
				Nov.doCmd(() => {
					size = value;
					eSizeChanged?.Invoke(this);
				},() => {
					size = old;
					eSizeChanged?.Invoke(this);
				});
			}
		}

		internal void focusChangeName(string new_string) {
			name = new_string;
		}

		public ViewFeature(IItem parent, string name) : base(parent, name) {}

		public override IFeature Clone(IItem parent) {
			ViewFeature var = new ViewFeature(parent, Name);
			var.location = location;
			return var;
		}
		//### 显示-主线,250,300,
		protected override void writeDatas(StringBuilder sb) {
			sb.Append(delimiter);
			sb.Append(location.X.ToString());
			sb.Append(delimiter);
			sb.Append(location.Y.ToString());
			sb.Append(delimiter);
			sb.Append(size.Width.ToString());
			sb.Append(delimiter);
			sb.Append(size.Height.ToString());
			return;
		}
		public override void loadData(string[] ss) {
			location = new Point(Int32.Parse(ss[1]), Int32.Parse(ss[2]));
			size = new Size(Int32.Parse(ss[3]), Int32.Parse(ss[4]));
		}
	}
}
